﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace AltimilliaLibrary
{
    public class Animation
    {
        public AnimationData AnimData;
        private float FrameLength;
        private int currentFrame;
        private int TotalFrames;
        private float totalElapsedTime;
        private string currentBehaviour;
        private int FPS;

        public Animation(AnimationData Data, int FPS)
        {
            this.FPS = FPS;
            currentFrame = 0;
            TotalFrames = Data.Rectangles.Count;
            FrameLength = 1.0f / this.FPS;
            totalElapsedTime = 0;
            AnimData = Data;
        }

        public String CurrentBehaviour
        {
            get
            {
                return currentBehaviour;
            }
            set
            {
                currentBehaviour = value;
                currentFrame = 0;
                TotalFrames = this.AnimData.Behavior[currentBehaviour].Count;
            }
        }

        public Frame CurrentFrame
        {
            get
            {
                return AnimData.Behavior[currentBehaviour][currentFrame];
            }
        }

        public void UpdateFrame(float elapsedTime)
        {
            totalElapsedTime += elapsedTime;
            if (totalElapsedTime >= FrameLength)
            {
                currentFrame++;
                currentFrame %= TotalFrames;
                totalElapsedTime %= FrameLength;
            }
        }
    }
}
